<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">供应商待审核</span>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="操作"
          width="210">
          <template scope="s">
            <el-button type="success" size="mini" v-if="s.row.myState === 1" @click="tableAuditing(s.row)" round>审核</el-button>
            <el-button type="danger" v-if="s.row.myState === 1" size="mini" @click="rejectOpen(s.row)" round>驳回</el-button>
            <el-button type="warning" size="mini" @click="dialogSearchOpen(s.row)" round>轨迹</el-button>
            <el-tag type="primary" v-if="s.row.bxSupplierState === 3" class="tag">审核中</el-tag>
            <el-tag type="success" v-if="s.row.bxSupplierState === 4" class="tag">已审核</el-tag>
            <el-tag type="danger" v-if="s.row.bxSupplierState === 5" class="tag">已驳回</el-tag>
          </template>
        </el-table-column>
        <el-form-item label="名称" prop="bxSupplierName">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierName"
                    placeholder="供应商名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item prop="bxSupplierDepartmentid" label="所属部门">
          <el-cascader
            :options="DEPARTMENT.department"
            v-model="autoVue_table_bxSupplierDepartmentid"
            :show-all-levels="false"
            ref="departmentId"
            clearable
            filterable
            change-on-select
            :props="{
                  value: 'key',
                }"
            placeholder="所属部门"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="结算周期" prop="bxSupplierSetlecircle">
          <el-select v-model="autoVue_table_bxSupplierSetlecircle"
                     filterable
                     remote
                     placeholder="请选择结算周期">
            <el-option
              v-for="item in dialog.bxSupplierSetlecircle"
              :key="item.id"
              :label="item.text"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开户银行" prop="bxSupplierBank">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierBank"
                    placeholder="开户银行" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <!--
        <el-form-item label="账户名称" prop="bxSupplierAccount">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierAccount"
                    placeholder="账户名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="开户行" prop="bxSupplierBank">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierBank"
                    placeholder="开户行" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="银行账号" prop="bxSupplierBankaccount">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierBankaccount"
                    placeholder="银行账号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="供应商编码" prop="bxSupplierCode">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierCode"
                    placeholder="供应商编码" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="签订时间" prop="bxSupplierContracttime">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierContracttime"
                    placeholder="签订时间" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="是否签订合同" prop="bxSupplierIscontract">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierIscontract"
                    placeholder="是否签订合同" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="联系方式" prop="bxSupplierPhone">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierPhone"
                    placeholder="联系方式" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="bxSupplierSelfno">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierSelfno"
                    placeholder="身份证号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="结算周期" prop="bxSupplierSetlecircle">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierSetlecircle"
                    placeholder="结算周期" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="bxSupplierState">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierState"
                    placeholder="状态" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="一级分类" prop="bxSupplierTypeF">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierTypeF"
                    placeholder="一级分类" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="二级分类" prop="bxSupplierTypeS">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierTypeS"
                    placeholder="二级分类" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        -->
      </s-table>
    </el-card>
    <s-dialog :dialog="dialogUpload">
      <p slot="title">申请审核供应商 <span v-if="dialogUpload.row.bxSupplierName">供应商名称：{{dialogUpload.row.bxSupplierName}}</span></p>
      <s-form :form="formDialogUpload" ref="formDialogUpload">
        <el-row>
          <el-col :xs="24" :lg="{span: 23, offset: 0}" class="">
            <el-form-item prop="userId" label="审核人">
              <el-select v-model="formDialogUpload.userId"
                         filterable
                         placeholder="请选择">
                <el-option
                  v-for="item in dialogUpload.userId"
                  :key="item.id"
                  :label="item.name + '   ' + item.orgName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogUploadSave">保存</el-button>
    </s-dialog>
    <process ref="process"></process>
    <reject @success="rejectSuccess" ref="reject" type="information"></reject>
  </div>
</template>

<script>
  import {AutoVue, AutoPromise} from '~/plugins/Tools';

  function __form () {
    return {
      id: {value: '', rule: [], cRemarks: ''},
      bxSupplierName: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierCode: {value: '', rule: ['vNull'], cRemarks: '供应商'},
      bxSupplierSelfno: {value: '', rule: ['vNull', 'vNumber'], cRemarks: '供应商'},
      bxSupplierPhone: {value: '', rule: [], cRemarks: ''},
      bxSupplierTypeF: {value: '', rule: ['vNull__change'], cRemarks: '供应商'},
      bxSupplierTypeS: {value: '', rule: ['vNull__change'], cRemarks: '供应商'},
      bxSupplierSetlecircle: {value: '', rule: ['vNull__change'], cRemarks: ''},
      bxSupplierIscontract: {value: '', rule: ['vNull'], cRemarks: '供应商'},
      bxSupplierContracttime: {value: '', rule: ['vNull__change'], type: 'date', cRemarks: '供应商'},
      bxSupplierAccount: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierBank: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierBankaccount: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierOilcard: {value: '', rule: ['vNull', 'vNumber', 'vNumber100'], cRemarks: '供应商，油卡+现金=100%'},
      bxSupplierCash: {value: '', rule: ['vNull', 'vNumber', 'vNumber100'], cRemarks: '供应商，油卡+现金=100%'},
      bxSupplierIsinvoice: {value: '', rule: ['vNull'], cRemarks: '供应商'},
      bxSupplierInvoicetype: {value: '', rule: ['vNull__change'], cRemarks: '供应商'},
      bxSupplierState: {value: '', rule: [], cRemarks: ''},
    };
  }
  function __formDialogUpload () {
    return {
      userId: { value: '', rule: ['vNull'], cRemarks: '' },
    };
  }

  export default AutoVue({
    data: {
      table: {
        column: [
          {
            label: '供应商名称',
            prop: 'bxSupplierName',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '供应商编码',
            prop: 'bxSupplierCode',
            minWidth: '0px',
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '所属部门',
            prop: 'bxSupplierDepartmentname',
            searchName: 'bxSupplierDepartmentid',
            searchAfter: function (value) {
              return value.reverse()[0];
            },
            searchInitValue: function () {
              return [];
            },
            type: 'custom',
            search: true,
            minWidth: '220px',
            cRemarks: '不用填写',
          },
          {
            label: '联系方式',
            prop: 'bxSupplierPhone',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          /*
          {
            label: '更新时间',
            prop: 'updateDate',
            minWidth: '0px',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 6);
            },
            cRemarks: '不用填写',
            search: false,
          },
          */
          {
            label: '一级分类',
            prop: 'show_bxSupplierTypeF',
            minWidth: '0px',
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '更新人',
            prop: 'updateUserName',
            minWidth: '0px',
            cRemarks: '不用填写',
            search: false,
          },
          {
            label: '二级分类',
            prop: 'show_bxSupplierTypeS',
            minWidth: '0px',
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '结算周期',
            prop: 'show_bxSupplierSetlecircle',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '签订合同',
            prop: 'bxSupplierIscontract',
            minWidth: '0px',
            formatter: (row, column) => {
              return parseInt(row[column.property || column]) === 1 ? '否' : '是';
            },
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '合同开始',
            prop: 'bxSupplierContracttime_start',
            minWidth: '0px',
            cRemarks: '供应商',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
          },
          {
            label: '合同结束',
            prop: 'bxSupplierContracttime_end',
            minWidth: '0px',
            cRemarks: '供应商',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
          },
          {
            label: '账户名称',
            prop: 'bxSupplierAccount',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '开户行',
            prop: 'bxSupplierBank',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '银行账号',
            prop: 'bxSupplierBankaccount',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '油卡比例',
            prop: 'bxSupplierOilcard',
            minWidth: '0px',
            formatter: (row, column) => {
              return (row[column.property || column] * 100).toFixed(2) + ' %';
            },
            cRemarks: '供应商，油卡+现金=100%',
            search: false,
          },
          {
            label: '现金比例',
            prop: 'bxSupplierCash',
            minWidth: '0px',
            formatter: (row, column) => {
              return (row[column.property || column] * 100).toFixed(2) + ' %';
            },
            cRemarks: '供应商，油卡+现金=100%',
            search: false,
          },
          {
            label: '提供发票',
            prop: 'bxSupplierIsinvoice',
            minWidth: '0px',
            formatter: (row, column) => {
              return parseInt(row[column.property || column]) === 1 ? '否' : '是';
            },
            cRemarks: '供应商',
            search: false,
          },
          {
            label: '发票类型',
            prop: 'show_bxSupplierInvoicetype',
            minWidth: '0px',
            cRemarks: '供应商',
            search: false,
          },
          {
            label: '状态',
            prop: 'show_bxSupplierState',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
        ],
        key: 'id',
        url: '/supplier/searchWaitByPage',
        tableColumn: 5,
        muti: false,
      },
      formDialog: __form(),
      dialog: {
        title: '新增',
        bxSupplierSetlecircle: [],
        width: '80%',
      },
      formDialogUpload: __formDialogUpload(),
      dialogUpload: {
        row: {},
        ids: [],
        userId: [],
      },
    },
    transition: 'slide-fade-bottom',
    head: {
      'title': '供应商待审核',
      'meta': [
        {'hid': 'description', 'name': 'description', 'content': '乐速科技平台 资源管理 查看供应商待审核'},
      ],
    },
    store: [
      'INFORMATION',
      'DEPARTMENT',
      'DICTIONARY_information',
    ],
    methods: {
      dialogSearchOpen (row) {
        this.$refs.process.open(row);
      },
      tableAuditing (row) {
        if (!row.end) {
          this.dialogUploadOpen([], row);
        } else {
          this.$confirm('您将审批供应商。', '确认审批？', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
          }).then(async () => {
            await this.get('/supplier/review/' + row.id);
            this.tableWatch('table');
          });
        }
      },

      rejectOpen (row) {
        this.$refs.reject.open(row);
      },
      rejectSuccess (json) {
        this.tableWatch('table');
      },

      async dialogUploadOpen (ids, row) {
        let {contentList} = await this.get('/workflowConfig/selectAuditors/' + row.id);
        this.dialogUpload.userId = contentList;
        this.dialogUpload.row = row;
        this.dialogUpload.ids = ids;
        this.dialogUpload.visible = true;
      },
      dialogUploadSave () {
        this.VALIDATE('formDialogUpload', async option => {
          if (option.bxSupplierIscontract !== 2) {
            delete option.bxSupplierContracttime_start;
            delete option.bxSupplierContracttime_end;
          }
          try {
            await this.post('/supplier/readyreview', {
              ...option,
              id: this.dialogUpload.row.id,
            });
            this.dialogUpload.dialogInit.call(this);
            this.tableWatch('table');
          } catch (err) {
            console.error(err);
          }
        });
      },
    },
    mounted: async function () {
      this.tableWatch('table');
      this.USE('DEPARTMENT');
      await AutoPromise([
        async () => {
          this.dialog.bxSupplierSetlecircle = await this.get('/setlecvcle/setlecycleList');
        },
      ]);
      console.log(this);
    },
  });
</script>
